home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / graphics.17 / graphics / graphics-0.17 / plot2fig / alabel.c next >
Encoding:
C/C++ Source or Header  |  1991-03-12  |  2.7 KB  |  89 lines

  1. /* plot, unix plot file to graphics device translators.
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.  
  4.    plot is distributed in the hope that it will be useful, but WITHOUT
  5.    ANY WARRANTY.  No author or distributor accepts responsibility to
  6.    anyone for the consequences of using it or for whether it serves any
  7.    particular purpose or works at all, unless he says so in writing.
  8.    Refer to the GNU General Public License for full details.
  9.    
  10.    Everyone is granted permission to copy, modify and redistribute plot,
  11.    but only under the conditions described in the GNU General Public
  12.    License.  A copy of this license is supposed to have been given to you
  13.    along with plot so you can know your rights and responsibilities.  It
  14.    should be in a file named COPYING.  Among other things, the copyright
  15.    notice and this notice must be preserved on all copies.  */
  16.  
  17. #include "sys-defines.h"
  18. #include "libplot.h"
  19. #include "extern.h"
  20.  
  21. /* ALABEL takes three arguments X_JUSTIFY, Y_JUSTIFY, and S and places
  22.    the label S according to the x and y axis adjustments specified in
  23.    X_JUSTIFY and Y_JUSTIFY respectively.  X_JUSTIFY is a character
  24.    containing either l, c, or r for left, center or right justified with
  25.    respect to the current x coordinate.  Y_JUSTIFY is a character
  26.    containing either b, c, or t for placing the bottom center or top of
  27.    the label even with the current y coordinate. S is a string containing
  28.    the label. The current point is moved to follow the end of the text. */
  29.  
  30. int
  31. alabel (x_justify, y_justify, s)
  32.      int x_justify, y_justify;
  33.      char *s;
  34. {
  35.   int i;
  36.   char *p;
  37.   int x_justification = 0;
  38.   double y_offset = 0.;
  39.  
  40.   draw_line ();
  41.   switch( x_justify) {
  42.     case 'l':
  43.      x_justification = 0;
  44.      break;
  45.     case 'c':
  46.      x_justification = 1;
  47.      break;
  48.     case 'r':
  49.      x_justification = 2;
  50.      break;
  51.    }
  52.   switch( y_justify) {
  53.     case 't':
  54.      y_offset = 1.1;
  55.      break;
  56.     case 'c':
  57.      y_offset = 0.5;
  58.      break;
  59.     case 'b':
  60.      y_offset = 0.0;
  61.      break;
  62.    }
  63.  
  64.   /* ignore leading white space */
  65.   p = s;
  66.   while (isspace(*p))
  67.     p++;
  68.  
  69.   /* only output the string if it contains non-whitespace characters. */
  70.   if (strlen(p))
  71.     printf( "%d %d %d %d %d %d %d %.3f %d %d %d %d %d %s\1\n",
  72.        4,            /* text object */
  73.        x_justification,    /* horzontal justification */
  74.        font_id,        /* font */
  75.        (int) font_size,    /* point size */
  76.        0,            /* pen */
  77.        0,            /* color */
  78.        0,            /* depth */
  79.        text_rotation_angle,    /* angle of rotation (float) */
  80.        0,            /* flags */
  81.        8,            /* height (pixels) */
  82.        8,            /* length (pixels) */
  83.        (int) ((last_x - x_input_min)/ x_scale + x_output_min),
  84.        (int) ((last_y - y_input_min)/ y_scale + y_output_min
  85.           + font_size * y_offset * 72 / 80),
  86.        p);
  87.   return 0;
  88. }
  89.